function OS_Dialog(game,interface,winres,params)
{
	var activeKey=null;
	
	var width=500;
	if (!!params.width) width=params.width;
	
	var height=120;
	if (!!params.height) height=params.height;
	var currentHeight=0;
	
	var bottom=20;
	var top=null;
	if (params.position=="top") {bottom=null;top=20;}
	else if (params.position=="bottom") {bottom=20;top=null;}
	else if (params.position=="center") {bottom=null;top=null;}
	
	var duration=200;
	var startTime=0;
	var closingTime=0;
	
	var paddingL=30;
	var paddingT=15;
	var lineHeight=30;
	var fontSize=20;
	var paddingLp=10;//肖像边距
	
	this.contentWidth=width-paddingL*2;
	this.confirmFlag=0;
	this.drawList=[];
	
	var callback=params.callback;
	this.setCallback=function(cb)
	{
		callback=cb;
	}
	
	this.getHeight=function()
	{
		return height;
	}
	
	this.getPaddingT=function()
	{
		return paddingT;
	}
	
	this.getLineHeight=function()
	{
		return lineHeight;
	}
	
	this.interceptKey=function()
	{
		activeKey=null;
		var keys=["esc","enter","left","right","up","down","space"];
		for (var index in keys)
		{
			var key=keys[index];
			if (!!game.status.checkKeyPressed(key))
			{
				activeKey=key;
			}
		}
	}
	
	this.getActiveKey=function()
	{
		return activeKey;
	}
	
	this.open=function()
	{
		interface.setActiveDialog(this);
		startTime=(new Date()).getTime();
		closingTime=0;
	}
	
	this.close=function()
	{
		closingTime=(new Date()).getTime();
	}
	
	this.update=function()
	{
		this.drawList.splice(0);
		var timecost=(new Date()).getTime()-startTime;
		//如果对话框正要关闭
		if (closingTime>0)
		{
			timecost=(new Date()).getTime()-closingTime;
			if (timecost<duration)
			{
				currentHeight=height*Math.sin(Math.PI*0.5*(1-timecost/duration));
			}
			else
			{
				interface.setActiveDialog(null);
				if (!!callback)
				{
					callback();
				}
			}
		}
		//对话框正要开启
		else if (timecost<duration)
		{
			var timecost=(new Date()).getTime()-startTime;
			currentHeight=height*Math.sin(Math.PI*0.5*timecost/duration);
		}
		//更新对话框中的内容
		else
		{
			currentHeight=height;
			this.updateContent();
		}
	}
	
	this.updateContent=function()
	{
		game.error("未被重载的抽象函数");
	}
	
	this.drawSelf=function()
	{
		var dleft=game.config.width*0.5-width*0.5;
		var dtop=0;
		if (!!top) dtop=top;//居上
		else if (!!bottom) dtop=game.config.height-bottom-height*0.5-currentHeight*0.5;//居下
		else dtop=game.config.height*0.5-currentHeight*0.5;//居中
		game.stage.drawWindow(winres,dleft,dtop,width,currentHeight,this.confirmFlag);
		
		for (var i=0;i<this.drawList.length;i++)
		{
			var drawing=this.drawList[i];
			switch(drawing.type)
			{
				case "text":
					var text_temp=drawing.text.substr(0,drawing.textLen);
					var text_drawing={
						content:text_temp,
						bold:true,
						maxWidth:this.contentWidth,
						size:fontSize,
						color:drawing.disable?"rgba(255,255,255,0.5)":"#eee",
						shadow:{offsetX:1,offsetY:1,blur:1,color:"#000"},
						background:drawing.background
					};
					game.stage.write(text_drawing,dleft+paddingL,dtop+paddingT+drawing.line*lineHeight);
					break;
				case "name":
					var text_drawing={
						content:drawing.text,
						bold:true,
						size:fontSize,
						color:drawing.color,
						shadow:{offsetX:1,offsetY:1,blur:1,color:"#000"},
					};
					game.stage.write(text_drawing,dleft+paddingL,dtop+paddingT);
					break;
				case "portrait":
					var sheight=drawing.image.height;
					var swidth=drawing.image.width;
					var pheight=drawing.height;
					var pwidth=swidth*pheight/sheight;
					var ptop=dtop-pheight;
					var pleft=dleft+paddingLp;
					if (drawing.position=="right")
					{
						pleft=dleft+width-paddingLp-pwidth;
					}
					game.stage.getContext().drawImage(
						drawing.image,
						0,0,swidth,sheight,
						pleft,ptop,pwidth,pheight
					);
					break;
			}
		}
	}
}
